home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / comm / irc / AmIrc2Html.lha / AmIrc2Html.rexx < prev   
Encoding:
OS/2 REXX Batch file  |  1998-09-01  |  4.6 KB  |  186 lines

  1. /*
  2.    $VER: AmIrc2Html v1.1 (01-Sep-98) by D.F. Duck http://www.wordbench.com/dfd/
  3.    Converts AmIRC buffer/log to HTML.
  4. */
  5. options results
  6. parse arg infile' 'outfile' "'title'" 'flags
  7.  
  8. if length(infile)=0 | infile='?' then do
  9.   ver=sourceline(2)
  10.   parse var ver verl') 'verr
  11.   say '0C'x' 'strip(verl,'L','   $VER:')')'
  12.   say ' 'strip(verr)
  13.   say ' 'strip(sourceline(3))'0A'x
  14.   say 'Usage: rx AmIrc2Html <infile> <outfile> <"title text"> [-f-u]'
  15.   say
  16.   say '       infile = AmIRC log file to parse.'
  17.   say
  18.   say '      outfile = File to write output to.'
  19.   say
  20.   say ' "title text" = your html title text enclosed inside'
  21.   say '                double quote marks.'
  22.   say
  23.   say '           -f = filter out private /msg''s, /notice''s, and /whois'
  24.   say '                replies.' 
  25.   say '           -u = URL Grabber; add html links to url''s.'
  26.  
  27.   exit
  28. end
  29.  
  30. signal on break_c
  31. signal on syntax
  32.  
  33. if length(strip(title))=0 then title='My AmIRC Log'
  34. title=strip(title,'T','"')
  35. if upper(right(outfile,5))~='.HTML' then outfile=outfile'.html'
  36. call clear_vars
  37. c=0
  38. nopriv=0  ;if pos('-F',upper(flags))>0 then nopriv=1
  39. urlgrab=0 ;if pos('-U',upper(flags))>0 then urlgrab=1
  40.  
  41. if open(x,infile,'R') then do
  42.   call open(y,outfile,'W')
  43.   call writech(stdout,'Working..')
  44.   call writeln(y,'<HTML><HEAD><TITLE>'title'</TITLE></HEAD>')
  45.   call writeln(y,'<CENTER><H1>'title'</H1></CENTER>')
  46.   call writeln(y,'<BODY>')
  47.   call writeln(y,'<HR>')
  48.   call writeln(y,'<PRE>')
  49.   do until eof(x)
  50.     line = readln(x)
  51.     line = translate(line,' ','    ')
  52.     parse var line first' 'rest
  53.     if length(rest)=0 then iterate
  54.     c=c+1
  55.  
  56.     /* filter out private messages */
  57.     ok=1
  58.     if (nopriv) then do
  59.       firstL=left(first,1)
  60.       firstR=right(first,1)
  61.       select
  62.         when firstL='*' & firstR='*' then ok=0
  63.         when firstL='>' & firstR='<' then ok=0
  64.         when firstL='«' & firstR='»' then do
  65.           if pos('Whois',first)>0 then ok=0
  66.           if pos('Notify',first)>0 then ok=0
  67.         end
  68.         otherwise nop
  69.       end
  70.     end
  71.     if ~(ok) then iterate
  72.  
  73.  
  74.     if left(first,1)='<' & right(first,1)='>' then do
  75.       first=strip(first,'L','<')
  76.       first=strip(first,'T','>')
  77.     end
  78.  
  79.     /* filter out <>'s so it doesn't hose the html display */
  80.     p=''
  81.     do until p=0
  82.       p=pos('<',rest)
  83.       if p>0 then do
  84.         restr=left(rest,p-1)
  85.         restl=right(rest,length(rest)-(length(restr)+1))
  86.         rest=restr'<'restl
  87.       end
  88.     end
  89.     p=''
  90.     do until p=0
  91.       p=pos('>',rest)
  92.       if p>0 then do
  93.         restr=left(rest,p-1)
  94.         restl=right(rest,length(rest)-(length(restr)+1))
  95.         rest=restr'>'restl
  96.       end
  97.     end
  98.  
  99.     if length(rest)>65 then line.1=left(rest,lastpos(' ',rest,66))
  100.     else line.1=rest
  101.  
  102.     if length(rest)>length(line.1) then line.2=right(rest,length(rest)-length(line.1))
  103.  
  104.     /* call url checker */
  105.     if (urlgrab) then line.1=urlcheck(line.1)
  106.  
  107.     call writeln(y,left(first,10)'|'line.1)
  108.  
  109.     if length(line.2)>0 then do i = 2 to 6
  110.       j=i+1
  111.       if length(line.i)>66 then do
  112.         line.j = right(line.i,length(line.i)-lastpos(' ',line.i,66))
  113.         line.i = left(line.i,lastpos(' ',line.i,66))
  114.       end
  115.       /* call url checker */
  116.       if (urlgrab) then line.i=urlcheck(line.i)
  117.       if length(line.i)>0 then call writeln(y,left(' ',10)'|'line.i)
  118.     end
  119.  
  120.     call clear_vars
  121.     if c/50 = c%50 then call writech(stdout,'.')
  122.   end
  123.   call close(x)
  124.   call writeln(y,'</PRE>')
  125.   call writeln(y,'<P><HR>')
  126.   call writeln(y,'<CENTER><FONT SIZE=-1>Page created with AmIrc2Http 1.0 by <a href="http://www.wordbench.com/dfd/">D.F. Duck</a></FONT></CENTER>')
  127.   call writeln(y,'</BODY')
  128.   call writeln(y,'</HTML>')
  129.   call close(y)
  130.   call writeln(stdout,' All done!')
  131. end
  132. else say 'Error opening "'infile'"'
  133. exit
  134.  
  135. urlcheck:
  136. parse arg text
  137. utext=upper(text)
  138. if pos('HTTP://',utext)>0 | pos('HTTPS://',utext)>0 | pos('WWW.',utext)>0  then text=urlgrabber(text)
  139. if pos('&',text)>0 then text=insert('amp;',text,pos('&',text))
  140. return text
  141.  
  142. urlgrabber:
  143. parse arg text
  144. p=pos('HTTP://',utext)
  145. if p>0 then do
  146.   l = left(text,p-1)
  147.   t = right(text,length(text)-(p-1))
  148.   parse var t w' 'r
  149.   text=l'<A HREF="'w'">'w'</A> 'r
  150.   return text
  151. end
  152. p=pos('HTTPS://',utext)
  153. if p>0 then do
  154.   l = left(text,p-1)
  155.   t = right(text,length(text)-(p-1))
  156.   parse var t w' 'r
  157.   text=l'<A HREF="'w'">'w'</A> 'r
  158.   return text
  159. end
  160. p=pos('WWW.',utext)
  161. if p>0 then do
  162.   l = left(text,p-1)
  163.   t = right(text,length(text)-(p-1))
  164.   parse var t w' 'r
  165.   if length(w)=4 then break
  166.   text=l'<A HREF="http://'w'">'w'</A> 'r
  167. end
  168. return text
  169.  
  170. clear_vars:
  171. do i = 1 to 7
  172.   line.i=''
  173. end
  174. return
  175.  
  176. break_c:
  177. call close(x)
  178. call close(y)
  179. say 'CTRL-C detected, exiting.'
  180. exit
  181.  
  182. syntax:
  183. say 'Syntax error line 'sigl' :'errortext(rc)
  184. say '> 'sourceline(sigl)
  185. exit
  186.